Update curl_getinfo() return types
#4279
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds new return types for
curl_getinfo()for newCURLINFO_*constants that were added in recent PHP 8.x versions. It also corrects the return types of some existing options that were incorrect.I have also added the appropriate tests for all new constants and adjusted the existing ones.
Details
Note
Theoretically, every single option could potentially return
falseif the loaded curl library doesn't support it.1 However, as this is unlikely to happen in production, I decided to keep things mostly as they are, to avoid breaking any existing setups. I only addedfalseto the return type if the option is only available in newer cURL versions (>=8.0.0– March 20232), or if there is another specific reason for doing so.Changed Types
CURLINFO_REDIRECT_URL: Returns a string ifCURLOPT_FOLLOWLOCATIONis disabled,falseotherwise.CURLINFO_SIZE_UPLOAD,CURLINFO_SIZE_DOWNLOAD,CURLINFO_SPEED_DOWNLOAD,CURLINFO_SPEED_UPLOAD: Returns an integer.CURLINFO_PRIVATE: PHP treats this like a classic variable.3 I testednull|bool|int|float|string|array|object|resource.4CURLINFO_HTTP_CODE: (Legacy) alias ofCURLINFO_RESPONSE_CODEas of PHP 5.5 and cURL 7.10.8.CURLINFO_SSL_ENGINES,CURLINFO_COOKIELIST: Returns a list (instead of an indexed array).CURLINFO_CERTINFO: Returns a list of associative arrays (instead of an indexed array).CURLINFO_RTSP_SESSION_ID: Returns a string.56 Returnsfalseif no ID was set or if the protocol is notrtsp://.CURLINFO_PROTOCOL: Returns an integer, aCURLPROTO_*constant value:Added Types (PHP 8.2)
CURLINFO_EFFECTIVE_METHOD: Returns a string.CURLINFO_PROXY_ERROR: Returns an integer, aCURLPX_*constant value:CURLINFO_REFERER: Returns a string ifCURLOPT_FOLLOWLOCATIONandCURLOPT_AUTOREFERERare enabled,falseotherwise.CURLINFO_RETRY_AFTER: Returns an integer (number of seconds, even if theRetry-Afterheader is a timestamp string).Added Types (PHP 8.3)
CURLINFO_CAINFO: Returns a string for the CA file path orfalseif it is not set.CURLINFO_CAPATH: Returns a string for the CA directory orfalseif it is not set.Added Types (PHP 8.4)
CURLINFO_POSTTRANSFER_TIME_T: Returns an integer. Since cURL v8.10.0,falseotherwise.Note
PHP 8.4 introduced some more unrelated
CURLINFO_*constants, such asCURLINFO_DATA_INandCURLINFO_SSL_DATA_IN. These constants are not intended for use withcurl_getinfo(). Instead, they are used in the callback ofCURLOPT_DEBUGFUNCTION.Added Types (PHP 8.5)
CURLINFO_QUEUE_TIME_T: Returns an integer. Since cURL v8.6.0,falseotherwise.CURLINFO_USED_PROXY: Returns an integer, resprenting no/yes:falseotherwise.CURLINFO_HTTPAUTH_USED: Returns an integer (aCURLAUTH_*constant value). Since cURL v8.12.0,falseotherwise.CURLINFO_PROXYAUTH_USED: Returns an integer (aCURLAUTH_*constant value). Since cURL v8.12.0,falseotherwise.CURLINFO_CONN_ID: Returns an integer. Since cURL v8.2.0,falseotherwise.Sources
PHP Manual:
cURL Documentation
PHP.Watch
GitHub Repos
curl/curl:php/php-src:JetBrains/phpstorm-stubs:Footnotes
There are
RETURN FALSEfallbacks for every data type:php/php-src/ext/curl/interface.c#L2641-L2732 ↩cURL 8.0.0 release: https://curl.se/ch/8.0.0.html ↩
PHP uses the general
zvalcontainer data type for the private data:php/php-src/ext/curl/interface.c#L1966-L1967 ↩PHP Debugging Script (PHP 8.2.12 and cURL 8.4.0): https://gist.github.com/FeBe95/8a947dd392c1d1693cfc72eb9501d2c7 ↩
IETF RTSP RFC, section "3.4 Session Identifiers": https://www.ietf.org/rfc/rfc2326.txt ↩
The value of
CURLINFO_RTSP_SESSION_IDisCURLINFO_STRING + 36:curl/curl/include/curl/curl.h#L2962 ↩